package com.power.sifa.correction.model.pojo.bo;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.power.sifa.correction.converter.LocalDateConverter;
import com.power.sifa.correction.model.Crc_person;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName Crc_personExecelBO
 * @Author xiongzw
 * @Date 2023/12/6 16:45
 * @Description EXCEL导出类BO
 * @Version: 1.0
 **/

@Data
@HeadRowHeight(30)
@ContentRowHeight(20)
public class Crc_personExcelBO {


    @ExcelProperty(value = "人员编号(部)")
    @ColumnWidth(16)
    private String troopid;

    @ExcelProperty(value = "人员编号")
    @ColumnWidth(16)
    private String id;

    @ExcelProperty(value = "姓名")
    @ColumnWidth(16)
    private String name;

    @ExcelProperty(value = "性别")
    @ColumnWidth(16)
    private String gender;

    @ExcelProperty(value = "民族")
    @ColumnWidth(16)
    private String nation;

    @ExcelProperty(value = "文化程度")
    @ColumnWidth(16)
    private String culture;

    @ExcelProperty(value = "矫正起日", converter = LocalDateConverter.class)
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @ColumnWidth(16)
    private LocalDate startdate;

    @ExcelProperty(value = "矫正止日", converter = LocalDateConverter.class)
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @ColumnWidth(16)
    private LocalDate enddate;

    @ExcelProperty(value = "出生日期", converter = LocalDateConverter.class)
    @ColumnWidth(16)
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate birthym;

    @ExcelProperty(value = "矫正类别")
    @ColumnWidth(16)
    private String crctype;

    @ExcelProperty(value = "入矫日期", converter = LocalDateConverter.class)
    @ColumnWidth(16)
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate enterdate;

    @ExcelProperty(value = "所属司法所")
    @ColumnWidth(16)
    private String deptid;

    @ExcelProperty(value = "定位电话")
    @ColumnWidth(16)
    private String phone;

    @ExcelProperty(value = "运营商类型")
    @ColumnWidth(16)
    private String operators;


    @ExcelProperty(value = "家庭住址")
    @ColumnWidth(16)
    private String addr;

    @ExcelProperty(value = "户籍信息")
    @ColumnWidth(16)
    private String domicile;

    @ExcelProperty(value = "身份证")
    @ColumnWidth(16)
    private String cardno;

    @ExcelProperty(value = "国籍")
    @ColumnWidth(16)
    private String nationality;

    @ExcelProperty(value = "户口类型")
    @ColumnWidth(16)
    private String housetype;

    @ExcelProperty(value = "原职业")
    @ColumnWidth(16)
    private String oricareer;

    @ExcelProperty(value = "就业就学")
    @ColumnWidth(16)
    private String perform;

    @ExcelProperty(value = "原政治面貌")
    @ColumnWidth(16)
    private String politics;

    @ExcelProperty(value = "婚姻状况")
    @ColumnWidth(16)
    private String marriage;

    @ExcelProperty(value = "是否有传染病史")
    @ColumnWidth(16)
    private String isinfect;

    @ExcelProperty(value = "宗教信仰")
    @ColumnWidth(16)
    private String religion;

    @ExcelProperty(value = "原判起日", converter = LocalDateConverter.class)
    @ColumnWidth(16)
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate oristartdate;

    @ExcelProperty(value = "原判止日", converter = LocalDateConverter.class)
    @ColumnWidth(16)
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate orienddata;

    @ExcelProperty(value = "刑种")
    @ColumnWidth(16)
    private String penalty;

    @ExcelProperty(value = "入矫类别")
    @ColumnWidth(16)
    private String entertype;

    @ExcelProperty(value = "矫正期限")
    @ColumnWidth(16)
    private String timelong;

    @ExcelProperty(value = "报到时间", converter = LocalDateConverter.class)
    @ColumnWidth(16)
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate reportdate;

    @ExcelProperty(value = "报到情况")
    @ColumnWidth(16)
    private String reportsit;

    @ExcelProperty(value = "犯罪类型")
    @ColumnWidth(16)
    private String crime;

    @ExcelProperty(value = "操作")
    @ColumnWidth(16)
    private String operation;


    @ExcelProperty(value = "社区矫正决定机关类型")
    @ColumnWidth(16)
    private String organtype;


    @ExcelProperty(value = "社区矫正决定机关名称")
    @ColumnWidth(16)
    private String organname;


    /**
     * 对象转excelBo
     * @param person
     * @return
     */
    public static Crc_personExcelBO convertToExcel(Crc_person person) {
        Crc_personExcelBO excelBO = new Crc_personExcelBO();
        excelBO.setTroopid(person.getTroopid());
        excelBO.setId(person.getId());
        excelBO.setName(person.getName());

        if (StringUtils.isNotEmpty(person.getGender_text())) {
            excelBO.setGender(person.getGender_text());
        }
        if (StringUtils.isNotEmpty(person.getNation_text())) {
            excelBO.setNation(person.getNation_text());
        }
        if (StringUtils.isNotEmpty(person.getCulture_text())) {
            excelBO.setCulture(person.getCulture_text());
        }
        excelBO.setStartdate(ObjectUtil.isNotEmpty(person.getStartdate()) ? person.getStartdate().toInstant()
                .atZone(ZoneId.systemDefault()).toLocalDate() : null);
        excelBO.setEnddate(ObjectUtil.isNotEmpty(person.getEnddate()) ? person.getEnddate().toInstant()
                .atZone(ZoneId.systemDefault()).toLocalDate() : null);

        excelBO.setBirthym(ObjectUtil.isNotEmpty(person.getBirthym()) ? person.getBirthym().toInstant()
                .atZone(ZoneId.systemDefault()).toLocalDate() : null);
        if (StringUtils.isNotEmpty(person.getCrctype_text())) {
            excelBO.setCrctype(person.getCrctype_text());
        }

        excelBO.setEnterdate(ObjectUtil.isNotEmpty(person.getEnterdate()) ? person.getEnterdate().toInstant()
                .atZone(ZoneId.systemDefault()).toLocalDate() : null);

        excelBO.setDeptid(person.getDeptname());
        excelBO.setPhone(person.getPhone());
        excelBO.setOperators(ObjectUtil.isNotNull(person.getOperators()) ? person.getOperators().toString() : null);
        excelBO.setAddr(person.getAddr());
        excelBO.setDomicile(person.getDomicile());
        excelBO.setCardno(person.getCardno());
        excelBO.setNationality(person.getNationality_text());
        excelBO.setHousetype(person.getHousetype_text());
        excelBO.setOricareer(person.getOricareer());

        excelBO.setPerform(person.getPerform_text());
        excelBO.setPolitics(person.getPolitics_text());
        excelBO.setMarriage(person.getMarriage_text());
        excelBO.setIsinfect(person.getIsinfect_text());
        excelBO.setReligion(person.getReligion());

        excelBO.setOristartdate(ObjectUtil.isNotEmpty(person.getOristartdate()) ? person.getOristartdate().toInstant()
                .atZone(ZoneId.systemDefault()).toLocalDate() : null);
        excelBO.setOrienddata(ObjectUtil.isNotEmpty(person.getOrienddata()) ? person.getOrienddata().toInstant()
                .atZone(ZoneId.systemDefault()).toLocalDate() : null);

        excelBO.setPenalty(person.getPenalty_text());
        excelBO.setEntertype(person.getEntertype_text());
        excelBO.setTimelong(person.getTimelong());
        excelBO.setReportdate(ObjectUtil.isNotEmpty(person.getReportdate()) ? person.getReportdate().toInstant()
                .atZone(ZoneId.systemDefault()).toLocalDate() : null);
        excelBO.setReportsit(person.getReportsit());
        excelBO.setCrime(person.getCrime());
        excelBO.setOperation(person.getOperation());
        excelBO.setOrgantype(person.getOrgantype_text());
        excelBO.setOrganname(person.getOrganname());

        return excelBO;
    }


    /**
     * 对象转excelBo
     * @param personList
     * @return
     */
    public static List<Crc_personExcelBO> convertListToExcel(List<Crc_person> personList) {
        List<Crc_personExcelBO> excelBOList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(personList)) {
            for (Crc_person person : personList) {
                excelBOList.add(convertToExcel(person));
            }
        }
        return excelBOList;
    }

}
